/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package assignment2.stub;

import assignment2.data.Categories;
import assignment2.data.CategoriesFacade;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author tuan
 */
public class CategoryTbl_Stub {
    CategoriesFacade categoriesFacade = lookupCategoriesFacadeBean();

    public void insert(Categories category){
    categoriesFacade.create(category);
    }
    public void remove(Categories cate){
    categoriesFacade.remove(cate);
    
    }
    public void modify(Categories cate){
        categoriesFacade.edit(cate);
    }
    public Categories seachByID(String categoryID){
        return categoriesFacade.find(categoryID);
    }
    public List<Categories> listAll(){
    return categoriesFacade.findAll();
    }
    private CategoriesFacade lookupCategoriesFacadeBean() {
        try {
            Context c = new InitialContext();
            return (CategoriesFacade) c.lookup("java:global/Assignment2/Assignment2-ejb/CategoriesFacade!assignment2.data.CategoriesFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
    
}
